package com.tgy.myplus.others;
import com.tgy.myplus.entity.Picture;
import com.tgy.myplus.service.impl.PictureServiceImpl;
import com.yzk18.GUI.*;
import com.yzk18.commons.*;


import javax.annotation.Resource;

public class dealFile {
    @Resource
    Picture picture;
    @Resource
    PictureServiceImpl pictureService;

    public void savePng() {
        String fileName = GUI.fileOpenBox("666");
        System.out.println(fileName);
        byte [] fileByte = IOHelpers.readAllBytes(fileName);
        Picture picture = new Picture();
        picture.setId(2);
        picture.setFilebyte(fileByte);
        picture.setFilename(IOHelpers.getFileName(fileName));
        //System.out.println(Arrays.toString(fileByte));
        PictureServiceImpl pictureService = new PictureServiceImpl();
        int a = pictureService.insert(picture);
    }

    public void getPng(){
        int id = 1;
        Picture picture = pictureService.queryById(id);
        //System.out.println(picture.getFilebyte());
        byte [] fileByteOut = picture.getFilebyte();
        IOHelpers.writeAllBytes("D:/"+picture.getFilename(),fileByteOut);
    }


}
